import { useSystemInfo } from '@/store/system'

let cur_page = ''
let pre_page = ''

const Mixin = {
  onLoad() {
    console.log('Mixin onLoad')
  },
  onShow() {
    const { in_duration } = storeToRefs(useSystemInfo())
    console.log('Mixin onShow')
    in_duration.value = Date.now()
    const pages = getCurrentPages()
    if (pages.length) {
      const page = pages[pages.length - 1]
      cur_page = `/${page.route}`
      if (pages.length > 1)
        pre_page = `/${pages[pages.length - 2].route}`

      console.log(`%c从${pre_page}页面跳转到${cur_page},开始计时,${in_duration.value}`, 'color:#50a14f;background:#fff;')
    }
  },
  onHide() {
    const { view_duration, in_duration } = storeToRefs(useSystemInfo())
    console.log('Mixin onHide')
    view_duration.value = Date.now() - in_duration.value
    console.log(`%c在${cur_page}停留了${view_duration.value}毫秒`, 'color:#50a14f;background:#fff;')
  },
  onUnload() {
    const { view_duration, in_duration } = storeToRefs(useSystemInfo())
    console.log('Mixin onUnload')
    view_duration.value = Date.now() - in_duration.value
    console.log(`%c在${cur_page}停留了${view_duration.value}毫秒，上一页是${pre_page}`, 'color:#50a14f;background:#fff;')
  },
}

export default Mixin
